﻿import { WriteCommand } from '../../Libs/NetWork/WriteCommand/WriteCommand';
import { GameDataManager } from './../../Libs/Framework/Managers/GameDataManager';
import { FModule } from "../../Libs/Framework/Support/FModule";
import {EventManager} from "../../Libs/Framework/Managers/EventManager";
import {ModuleEvent} from "../../Libs/Framework/Event/ModuleEvent";
import {ModuleNames} from "../../Libs/Framework/Enums/ModuleNames";
import { WriteCmdEvent } from '../../Libs/Framework/Event/WriteCmdEvent';

export default class CreateDeskModule extends FModule {
    public get assets(): any { return ["Lobby/createDesk"] }
    private _close : cc.Node = null
    private _creater : cc.Node = null

    protected createViews() {
        super.createViews()
        this._close = this.node.getChildByName("Background").getChildByName("close")
        this._creater = this.node.getChildByName("Background").getChildByName("create")

        this._close.on(cc.Node.EventType.TOUCH_END, this.close, this);
        this._creater.on(cc.Node.EventType.TOUCH_END, this.CreaterDesk, this);
    }

    private displayPanl(s:string) : void {
        let data = GameDataManager.config.deskConfig[s];
    }

    private CreaterDesk() : void{
        new WriteCommand(WriteCmdEvent.CMD_CreaterDesk,1)
    }

    private close() : void {
        EventManager.dispatchModuleEventWith(ModuleEvent.DISPOSE_MODULE, ModuleNames.CreateDesk);
        EventManager.dispatchModuleEventWith(ModuleEvent.DISPOSE_MODULE, ModuleNames.Mask)
    }

    public dispose(): void {
        super.dispose();
        //this._creater.on(cc.Node.EventType.TOUCH_END, this.CreaterDesk);
        //this._close.off(cc.Node.EventType.TOUCH_END, this.close)
    }

    /*
    *
    * //console.log(GameDataManager.config.deskConfig)
        // this.leftBar = this.node.getChildByName('LeftBar');
        // this.toggleGroup = this.leftBar.getComponent(cc.ToggleGroup);
        // this.leftBar.removeAllChildren();
        // let strs: string[] = ['斗地主', '炸金花', '四川麻将', '广东麻将', '上海麻将'];

        // strs.forEach(str => {
        //     let t: cc.Node = ResouceManager.InstantiatePrefab('Common/GameToggle');
        //     let s: GameToggle = t.getComponent(GameToggle);
        //     s.setTextAndGroup(str, this.toggleGroup);
        //     this.leftBar.addChild(t);
        // });

        // console.log(this.toggleGroup.toggleItems);*/
}